angular.module('Caltech.factories', []).factory('principal', function ($state, $q, Constants, $timeout) {
    return {
        checkIfRoleMatched: function (roleName, $stateParams, notAuthorizedUrl) {
            var defer = $q.defer();    
            
            if (Constants.accountInfo.roleName === roleName) {
                $timeout(function() {
                    $state.go(notAuthorizedUrl, $stateParams);      
                    return $q.reject('Not authorized');
                });
                
                return defer.promise;
            }
        }
    };
});